<?
load_model('Common');
class Message extends Common {
	protected $_name ="message";
	protected $_primary = 'mes_id';
	
	public function get_message_list($where=null,$order='mes_id desc',$count=null,$offset=null){
		$arr = $this->fetchAll($where,$order,$count,$offset)->toArray();
		return $arr;
	}
	
	public function get_tenmes(){
		$db = $this->getAdapter();
		$sql = "select * from zf_message order by mes_date desc limit 10";
		return $db->fetchAll($sql);
	}
	
	public function get_message_info($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('mes_id = ?', $id);
		return $this->fetchRow($where)->toArray();
	}
	/**
	 * 根据where获取指定字段信息
	 *
	 * @param unknown_type $field
	 * @param unknown_type $where
	 * @return string/int 
	 */
	function get_mes_one($field,$where){
		$db = $this->getAdapter();
		$sql = "select $field from zf_message where $where";
		return $db->fetchOne($sql);
	}
	
	/**
	 *
	 * @param unknown_type $data
	 * @return 返回刚插入的id
	 */
	function add_mes($data){
		$dataInsert = array(
		    'mes_writer' => $data['mes_writer'],
		    'mes_content'=> $data['mes_content'],
		    'mes_date'   => $data['mes_date'],
		    'mes_ip'   => $data['mes_ip'],
		);
		return $this->insert($dataInsert);
	}
	
	function update_mes($id, $data){
		$db = $this->getAdapter();
		$where = $db->quoteInto('mes_id = ?', $id);
		return $this->update($data, $where);
	}
	
	function del_mes($id){
		$db = $this->getAdapter();
		$where = $db->quoteInto('mes_id = ?', $id);
		return $this->delete($where);
	}
	
	
}

?>